/**
  * @brief  二进制转八进制
  * @param  source 数组
  * @param  dest 数组
  * @param  sourceLen 长度
  * @return none
  * @note   none
  */
void BinToOct(const unsigned char *source, char *dest, int sourceLen){
    int i;
    for(i = 0; i < sourceLen; i++){
        dest[i * 3] = source[i] / 64 + '0';
        dest[i * 3 + 1] = source[i] / 8 % 8 + '0';
        dest[i * 3 + 2] = source[i] % 8 + '0';
    }
    dest[i * 3] = '\0';
}

/**
  * @brief  二进制转十进制
  * @param  p_data 数组
  * @param  len 长度
  * @return result
  * @note   none
  */
unsigned long CharToInt_long(unsigned char *p_data, unsigned char len){
    unsigned long result = 0;
    unsigned char i;
    for(i = 0; i < len; i++){
        result = result * 10 + p_data[i];
    }
    return result;
}

/**
  * @brief  二进制转十六进制
  * @param  source 数组
  * @param  dest 数组
  * @param  sourceLen 长度
  * @return none
  * @note   none
  */
void CharToHexByte(const unsigned char *source, char *dest, int sourceLen){
    int i;
    for(i = 0; i < sourceLen; i++){
        dest[i * 2] = source[i] / 16 + '0';
        dest[i * 2 + 1] = source[i] % 16 + '0';
    }
    dest[i * 2] = '\0';
}

/**
  * @brief  八进制转二进制
  * @param  source 数组
  * @param  dest 数组
  * @param  sourceLen 长度
  * @return none
  * @note   none
  */
void OctToBin(const char *source, unsigned char *dest, int sourceLen){
    int i;
    for(i = 0; i < sourceLen; i++){
        dest[i] = (source[i * 3] - '0') * 64 + (source[i * 3 + 1] - '0') * 8 + (source[i * 3 + 2] - '0');
    }
}

/**
  * @brief  八进制转十进制
  * @param  source 数组
  * @param  len 长度
  * @return result
  * @note   none
  */
unsigned long OctToInt(const char *source, unsigned char len){
    unsigned long result = 0;
    unsigned char i;
    for(i = 0; i < len; i++){
        result = result * 8 + (source[i] - '0');
    }
    return result;
}

/**
  * @brief  八进制转十六进制
  * @param  source 数组
  * @param  dest 数组
  * @param  sourceLen 长度
  * @return none
  * @note   none
  */
void OctToHex(const char *source, char *dest, int sourceLen){
    int i;
    for(i = 0; i < sourceLen; i++){
        dest[i * 2] = source[i * 3] - '0';
        dest[i * 2 + 1] = source[i * 3 + 1] - '0';
    }
    dest[i * 2] = '\0';
}

/**
  * @brief  十进制转二进制
  * @param  source 数组
  * @param  dest 数组
  * @param  len 长度
  * @return none
  * @note   none
  */
void IntToChar(unsigned long source, unsigned char *dest, unsigned char len){
    unsigned char i;
    for(i = 0; i < len; i++){
        dest[i] = source % 2;
        source = source / 2;
    }
}

/**
  * @brief  十进制转八进制
  * @param  source 数组
  * @param  dest 数组
  * @param  len 长度
  * @return none
  * @note   none
  */
void IntToOct(unsigned long source, char *dest, unsigned char len){
    unsigned char i;
    for(i = 0; i < len; i++){
        dest[i * 3] = source / 64 + '0';
        source = source % 64;
        dest[i * 3 + 1] = source / 8 + '0';
        source = source % 8;
        dest[i * 3 + 2] = source + '0';
        source = 0;
    }
    dest[i * 3] = '\0';
}

/**
  * @brief  十进制转十六进制
  * @param  source 数组
  * @param  dest 数组
  * @param  len 长度
  * @return none
  * @note   none
  */
void IntToHexByte(unsigned long source, char *dest, unsigned char len){
    unsigned char i;
    for(i = 0; i < len; i++){
        dest[i * 2] = source / 16 + '0';
        dest[i * 2 + 1] = source % 16 + '0';
        source = source / 16;
    }
    dest[i * 2] = '\0';
}

/**
  * @brief  十六进制转二进制
  * @param  source 数组
  * @param  dest 数组
  * @param  sourceLen 长度
  * @return none
  * @note   none
  */
void HexToChar(const char *source, unsigned char *dest, int sourceLen){
    int i;
    for(i = 0; i < sourceLen; i++){
        dest[i] = (source[i * 2] - '0') * 16 + (source[i * 2 + 1] - '0');
    }
}

/**
  * @brief  十六进制转八进制
  * @param  source 数组
  * @param  dest 数组
  * @param  sourceLen 长度
  * @return none
  * @note   none
  */
void HexToOct(const char *source, char *dest, int sourceLen){
    int i;
    for(i = 0; i < sourceLen; i++){
        dest[i * 3] = source[i * 2] - '0';
        dest[i * 3 + 1] = source[i * 2 + 1] - '0';
    }
    dest[i * 3] = '\0';
}

/**
  * @brief  十六进制转十进制
  * @param  source 数组
  * @param  sourceLen 长度
  * @return result
  * @note   none
  */
unsigned long HexToInt(const char *source, int sourceLen){
    unsigned long result = 0;
    int i;
    for(i = 0; i < sourceLen; i++){
        result = result * 16 + (source[i * 2] - '0') * 16 + (source[i * 2 + 1] - '0');
    }
    return result;
}
